@page "/PortForward"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Utils
@using Entity
@using k8s.Models
@inherits BlazorApp.Pages.Common.TableBase<Entity.PortForward>
@if (TableData.PagedItems != null)
{
    <Card Bordered="false" Hoverable="true">
        <TitleTemplate>
            <SearchToolBar Title=@L["PortForward"] Count="@TableData.Total"
                           OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                           OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                           OnRemoveAllClicked="@TableData.RemoveAllSelection" TableData="@TableData"
                           OnSearch="OnSearchHandler" TItem="PortForward"
                           OnNsSelected="OnNsSelectedHandler">
            </SearchToolBar>
        </TitleTemplate>
        <ChildContent>
            <Body>

            <Table TItem="PortForward"
                   DataSource="@TableData.PagedItems"
                   Size=@TableSize.Small Bordered="true"
                   Total="TableData.Total"
                   @bind-PageIndex="TableData.PageIndex"
                   @bind-PageSize="TableData.PageSize"
                   @bind-SelectedRows="TableData.SelectedRows"
                   Loading="TableData.Loading"
                   OnChange="OnPageChangeHandler">
                <Selection Key="@(context.Name())"/>
                <AntDesign.Column Field="@context.Name()" Title=@L["Name"]>
                    <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                </AntDesign.Column>
                <AntDesign.Column Field="@context.LocalPort" Title=@L["KubeName"]>
                    <RefView FullView="true"
                             Ref="@KubeHelper.GetObjectRef(context.Type.ToString(), context.Namespace(), context.KubeName)">
                    </RefView>
                </AntDesign.Column>
                <AntDesign.Column Field="@context.KubePort" Title=@L["KubePort"]/>
                <AntDesign.Column Field="@context.LocalPort" Title=@L["LocalPort"]>
                    <div>
                        @context.LocalPort
                        <a href=@($"http://127.0.0.1:{context.LocalPort}") target="_blank">Http</a>
                        <a href=@($"https://127.0.0.1:{context.LocalPort}") target="_blank">Https</a>
                    </div>
                </AntDesign.Column>
                <AntDesign.Column Field="@context.Status" Title=@L["Status"]/>
                <AntDesign.Column Field="@context.StatusTimestamp" Title=@L["Probe"]/>
                <AntDesign.Column Title=@L["Age"] TData="string" Width="100px">
                    <AgeView Age="@context.CreationTimestamp()"></AgeView>
                </AntDesign.Column>
                <ActionColumn Title=@L["Action"] Width="100px">
                    <PortForwardAction Item="@context"></PortForwardAction>
                </ActionColumn>
            </Table>
            </Body>
        </ChildContent>

    </Card>
    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="PortForward"></ResourceWatcher>
}
